package com.haozi.ehub.admin.config;

import com.haozi.ehub.core.util.CodeUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * MVC相关配置
 * @author ：terry
 * @date ：Created in 2020/6/12 14:52
 * @version: 1.0
 */
@Slf4j
//@Component
//@Configuration
public class WebMvcConfig implements WebMvcConfigurer{

    /**
     * 不知有没有起作用的跨域配置
     * @author ： terry
     * @date ： Created in 2020/6/12 15:02
     * @return： WebMvcConfigurer
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        log.info("Into WebMvcConfig class addCorsMappings method");
        List<String> list = new ArrayList<>();
        list.add(CodeUtils.GET_U);
        list.add(CodeUtils.PUT_U);
        list.add(CodeUtils.POST_U);
        list.add(CodeUtils.DELETE_U);
        list.add(CodeUtils.OPTIONS_U);
        final String[] methods = list.toArray(new String[list.size()]);
        registry.addMapping(CodeUtils.URL_ALL).allowedMethods(methods);
        log.info("Execute WebMvcConfig class addCorsMappings method");
    }
}
